<table id="card_manage_data" data-options="fit:true"></table>
<div id="find_manage_toolbar" style="padding:0 10px;">
	<input class="icon-add" type="button" value="办卡" onclick="javascript:openManageWin()"
		 style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
		 <input class="icon-reload" type="button" value="刷新" onclick="javascript:flushManage()"
		style="padding-left:20px;border:1px #999 solid;margin:2px;"/>
	<div style="float:right;margin-right:20px;">
		查询条件：
		<select id="mag_myselect" style="text-align:center;" >
			<option value="null">-- 请选择 --</option>
			<option value="学号">学号</option>
			<option value="卡号">卡号</option>
			<option value="卡状态">卡状态</option>
		</select>
		<input style="text-align:center;" type="text" id="mag_input_text">
		<input type="button" value="查询" onclick="javascript:findManage()"/>
	</div>
</div>
<script>
$(function(){
	$('#card_manage_data').datagrid({
		url:'../cardInfoServlet?t='+new Date(),
		queryParams:{op:"getCardInfo"},
		loadMsg:'数据加载中...',
	    fitColumns:true,
	    rownumbers:true,
	    striped:true,
		sortName:'sid',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'sid',title:'校园卡编号',width:100,align:'center'}, 
			{field:'studentId',title:'学号',width:100,align:'center',sortable:true},
			{field:'sname',title:'姓名',width:150,align:'center'}, 
			{field:'sclass',title:'班级',width:150,align:'center'}, 
			{field:'sdepartment',title:'院系',width:200,align:'center'}, 
			{field:'balance',title:'账号余额',width:100,align:'center'},
			{field:'status',title:'校园卡状态',width:150,align:'center',formatter:function(value,rowData,rowIndex){
				if(value == 1) {
					return "正常";
				} else if(value==2){
					return "挂失";
				}else if(value==3){
					return "弃用";
				}
			}}
		]],
		toolbar:"#find_manage_toolbar"
	});
});

function flushManage(){
	$('#card_manage_data').datagrid("reload");
}

//添加学生信息
function addCardInfo(){
	var studentId = $.trim($("#studentId_manage").val());
	//var sname = $.trim($("#sname").val());
	//var sclass = $.trim($("#sclass").val());
	//var sdepartment = $.trim($("#sdepartment").val());
	
	//为空判断
	if(sname != "" && sclass != "" && sdepartment != "") {
		$.post("../cardInfoServlet?t="+new Date(),
			{op:"addCardInfo",studentId:studentId},
			function(data){
			data = parseInt($.trim(data));
			if(data > 0) {
				$.messager.show({
					title:'成功提示',
					msg:'校园卡添加成功!',
					timeout:3000,
					showType:'slide'
				});
				$("#studentId_manage").val("");
				$("#sname").val("");
				$("#sclass").val("");
				$("#sdepartment").val("");
				
				$("#add_card_data").dialog("close");
				$('#card_manage_data').datagrid("reload");
			} else {
				$.messager.alert('错误提示','此卡已被注册!','error');
				$("#studentId_manage").val("");
				$("#sname").val("");
				$("#sclass").val("");
				$("#sdepartment").val("");
				$("#add_card_data").dialog("close");
			}
		});
	} else {
		$.messager.show({
			title:'温馨提示',
			msg:'您输入的信息不完整，请确认后再提交!',
			timeout:3000,
			showType:'slide'
		});
	}
}

//失焦
function openManageWin() {
$("#add_card_data").dialog("open");
	$("#studentId_manage").blur(function() {
		var studentId = $.trim($("#studentId_manage").val());
		if (studentId != null) {
			$.post("../cardInfoServlet?t="+new Date(), {
				op : "getAddCardInfo",studentId:studentId
			}, function(data) {
				if(parseInt($.trim(data))==0){
					$("#studentId_manage").val("");
					$.messager.alert('错误提示','数据库无此人信息，请核实!','error');
					$("#add_card_data").dialog("close");
				}else{
					$("#sname").val(data.stuInfo[0].sname);
					$("#sclass").val(data.stuInfo[0].sclass);
					$("#sdepartment").val(data.stuInfo[0].sdepartment);
				}
			},"json");
		}
	});
}
//查询
function findManage() {
	var myselect = $.trim($("#mag_myselect").val());
	var info = $.trim($("#mag_input_text").val());
	if (myselect != "null" && info != "") {
		$.post("../cardInfoServlet?t="+new Date(), {
			op : "selectCardInfo",myselect:myselect,info:info
		}, function(data) {
			if(parseInt($.trim(data))==0){
				$.messager.alert('错误提示','没有该信息!','error');
			}else if(data!=null){
				$('#card_manage_data').datagrid("loadData",data.rows);
			}
		},"json");
	} else {
		$.messager.show({
			title : '温馨提示',
			msg : '您输入的信息不完整，请确认后再提交!',
			timeout : 3000,
			showType : 'slide'
		});
	}
}
</script>
<div id="add_card_data" class="easyui-dialog" title="办卡" style="width:400px;height:280px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label for="studentId_manage">学号：</label><input type="text" id="studentId_manage">
		<br /> <br /> 
		<label for="sname">姓名：</label><input type="text" id="sname" disabled="disabled">
		<br /> <br />
		<label for="sclass">班级：</label><input type="text" id="sclass" disabled="disabled">
		<br /> <br />
		<label for="sdepartment">学院：</label><input type="text" id="sdepartment" disabled="disabled">
		<br /> <br />
		<input style="padding:5px 25px;" type="button" onclick="addCardInfo()" value="写卡">
	</p>
</div>

